const { join,resolve } = require("path");
const TerserPlugin = require('terser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')

const os = require('os');
module.exports = {
  output: {
    path: join(__dirname, '../dist/assets'),
    publicPath: '/assets/[name].[contenthash:5].bundule.[ext]',
    filename: 'scripts/[name].[contenthash:5].bundule.js',
    assetModuleFilename: '',
  },
  optimization: {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        parallel: os.cpus().length - 1,
      }),
    ],
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      title: 'webgis-generated',
      filename: 'index.html',
      template:resolve(__dirname,'../src/web/index-prod.html'),
      minify:{
        removeComments:true,
        collapseWhitespace:true,
        removeAttributeQuotes:true,
      }
    }), 
    new OptimizeCSSAssetsPlugin({
      assetNameRegExp:/\.css$/g,
      cssProcessor:require('cssnano'),
      cssProcessorOptions:{
        preset:[
          'default',
          {
            discardComments:{
              removeAll:true,
            }
          }
        ]
      },
    })
  ],
};
